var salt = sessionStorage.getItem('usersalt');

layui.use(['form', 'layer'], function() {
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : top.layer,
		$ = layui.jquery;
		
	if(!sessionStorage.getItem('username')) {
		layer.msg('请先登录');
		setTimeout("top.location.href='../../../index.html'", 1000);
	}
	
	/*------------------查看大图.start------------------*/
	window.lookbigpic = function(self) {
		var json = {
			"status": 1,
			"msg": "",
			"title": "",
			"id": 8,
			"start": 0,
			"data": [{
				"alt": "",
				"pid": 109,
				"src": url + "attachment/seekFile/" + self,
				"thumb": ""
			}]
		}
		layer.photos({
			photos: json,
			anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
		});
	}
	/*------------------查看大图.end------------------ */
	
	/*------------------编辑情况.start------------------ */
	var courseId = getQueryVariable("id");
	if (courseId != false) {
		initEditShow();
	}
	var course;
	function initEditShow(){
		$.ajax({
			url: url + "course/getInfo",
			dataType: "json",
			async: true,
			type: "post",
			data: {
				Token: salt,
				id : courseId
			},
			success: function(data){
				if (data.code == 0) {
					course = data.data;
					$("#name").html(course.name);
					var num = 1;
					var fileHtml = $('<div style="display:inline-block;position:relative;margin-right:45px;" id="picupfile' + num + '"  ><a style="color: blue;text-decoration: underline;" href="' + url + 'attachment/seekFile/' + course.attId + '" >' + course.attName + '</a>&nbsp;<a class = "layui-btn layui-btn-danger layui-btn-xs" onclick="downloadCourse(\'' + course.attId + '\')"> 下载 </div > ');
					$('#dataDiv').html(fileHtml);
					$("#postTypeName").html(course.postTypeName);
					$("#courseTypeName").html(course.courseTypeName);
					var idx = 1;
          var imgHtml;
					if(course.imgId){
            imgHtml = $('<div style="display:inline-block;position:relative;margin-right:20px;" id="picupdata' + idx + '"  ><img id="pic' + course.imgId + '" onclick="lookbigpic(\'' + course.imgId + '\')" src="' + url + 'attachment/seekFile/' + course.imgId + '" width="100px" height="100px" class="picsty"/></div>');
          }else{
            imgHtml = $('<div style="display:inline-block;position:relative;margin-right:20px;"><img src="../../../images/default.png" width="100px" height="100px" class="picsty"/></div>');
          }
					$('#coverDiv').html(imgHtml);
				} else {
					setTimeout(function(){
						layer.msg(data.msg);
					}, 1000);
					courseId = false;
				}
			},
			error: function(error){
				console.log("获取失败");
			}
		});
	}
	/*------------------编辑情况.end------------------ */
	
	/*------------------下载附件.start------------------ */
	window.downloadCourse = function(attId){
		window.open(url + '/attachment/seekFile/' + attId);
	}
	/*------------------下载附件.end------------------ */
});